package com.brodong.animal_remake.common.skills.Blindness;

import com.brodong.animal_remake.common.entities.monster.realization.SkillBasicEntity;
import com.brodong.animal_remake.common.skills.Currentskills;
import com.brodong.animal_remake.common.skills.UseskillGoal;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.Difficulty;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;

public class SkillBlindnessSpellGoal extends UseskillGoal {
    private int lastTargetId;

    public SkillBlindnessSpellGoal(SkillBasicEntity mo) {
        super(mo,20,20,100);
    }
    public SkillBlindnessSpellGoal(SkillBasicEntity mo,int CastWarmup,int Casting,int CastingInterval){
        super(mo,CastWarmup,Casting,CastingInterval);
    }
    public boolean canUse() {
        if (!super.canUse()) {
            return false;
        } else if (mob.getTarget() == null) {
            return false;
        } else if (mob.getTarget().getId() == this.lastTargetId) {
            return false;
        } else {
            return mob.level.getCurrentDifficultyAt(mob.blockPosition()).isHarderThan((float) Difficulty.NORMAL.ordinal());
        }
    }

    public void start() {
        super.start();
        LivingEntity livingentity = mob.getTarget();
        if (livingentity != null) {
            this.lastTargetId = livingentity.getId();
        }

    }

    protected void performSpellCasting() {
        mob.getTarget().addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 400), mob);
    }

    protected SoundEvent getSpellPrepareSound() {
        return SoundEvents.ILLUSIONER_PREPARE_BLINDNESS;
    }

    protected Currentskills getSpell() {
        return Currentskills.BLINDNESS;
    }
}
